const { exec } = require('../db/index')

const getList = async () => {
  const sql = `select * from users;`
  return await exec(sql)
}

const addUser = async ({username, password, realname}) => {
  const sql = `insert into users (username, password, realname) values ('${username}', '${password}' , '${realname}');`
  return await exec(sql)
}

const updateUser = async ({id, username, password, realname}) => {
  const sql = `update users set username='${username}', password='${password}', realname='${realname}' where id = ${id};`
  return await exec(sql)
}

const deleteUser = async (id) => {
  const sql = `delete from users where id = ${id};`
  return await exec(sql)
}

module.exports = {
  getList,
  addUser,
  updateUser,
  deleteUser
}